import { lazy } from 'react'
import { Redirect } from 'react-router'
import randerRoutes from '../utils/randerRoutes'
const Login = lazy(() => import('../pages/Login'))
const Layout = lazy(() => import('../layouts'))
const Home = lazy(() => import('../pages/Home'))
const Question = lazy(() => import('../pages/Question'))
const Video = lazy(() => import('../pages/Video'))
const Profile = lazy(() => import('../pages/Profile'))
const ProfileEdit = lazy(() => import('../pages/Profile/Edit'))
const Chat = lazy(() => import('../pages/Profile/Chat'))
const NotFound = lazy(() => import('../pages/404'))
const Feedback = lazy(() => import('../pages/Profile/Feedback'))
export const routes = [
  {
    path: '/login',
    exact: true,
    component: Login,
  },
  {
    path: '/profile/edit',
    exact: true,
    render: (props: { location: { pathname: string } }) =>
      randerRoutes(ProfileEdit, props.location),
  },
  {
    path: '/profile/chat',
    exact: true,
    render: (props: { location: { pathname: string } }) =>
      randerRoutes(Chat, props.location),
  },
  {
    path: '/profile/feedback',
    exact: true,
    component: Feedback,
  },
  {
    path: '/',
    exact: true,
    render: () => <Redirect to="/home" />,
  },
  {
    path: '/home',
    component: Layout,
    routes: [
      {
        path: '/home',
        exact: true,
        component: Home,
      },
      {
        path: '/home/question',
        exact: true,
        component: Question,
      },
      {
        path: '/home/video',
        exact: true,
        component: Video,
      },
      {
        path: '/home/profile',
        exact: true,
        render: (props: { location: { pathname: string } }) =>
          randerRoutes(Profile, props.location),
      },
    ],
  },
  {
    path: '*',
    component: NotFound,
  },
]
